import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";

const pathResolve = (dir: string) => resolve(__dirname, dir);


export default defineConfig(
    ({ mode }) => {
        const env = loadEnv(mode, __dirname)
        return {
            plugins: [vue()],
            build: {
                outDir: "dist",
                terserOptions: {
                    compress: {
                        keep_infinity: true,
                        drop_console: true,
                        drop_debugger: true,
                    },
                },
                chunkSizeWarningLimit: 1500,
            },
            resolve: {
                alias: {
                    src: pathResolve("./src"),
                    api: pathResolve("./src/api"),
                    router: pathResolve("./src/router"),
                    store: pathResolve("./src/store"),
                    views: pathResolve("./src/views"),
                    utils: pathResolve("./src/utils"),
                    components: pathResolve("./src/components"),
                    assets: pathResolve("./src/assets"),
                },
                extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
            },
            base: "./",
            server: {
                port: 3000,
                open: true,
                cors: true,

                proxy: {
                    "/api": {
                        target: env.VITE_SERVER_API,
                        changeOrigin: true,
                        secure: false,
                        rewrite: (path) => path.replace("/api", ""),
                    },
                },
            },
        }
    }
);
